/**
 *
 */
$(function () {
    // 获取url参数
    var urlParams = getQueryVariable();
    var id = null;
    init();

    function init(){
        var cd = urlParams["cd"];
        getInfo(cd);
    }

    // 获得数据接口
    function getInfo(id) {
        let params = {
            url: "/index/meeting/getbycd?cd="+id,
            sCallback: function (data) {
                successCallback(data)
            },
            eCallback: function (res) {
            }
        }
        requset(params);
    }

    // 详细信息成功的回调
    function successCallback(data) {
        id = data["id"];
        var codeHtml = $("#content").html();
        $.each(data, function (key, data) {
            if (key == "submitTime") {
                data  = datetimeFormatLong2String(data);
            }
            if (key == "typeId") {
                if(data == 0){
                    data = "专家";
                } else if(data == 1){
                    data = "需求";
                } else if(data == 2){
                    data = "成果";
                } else if(data == 3){
                    data = "服务";
                }
            }
            if (key == "fromerUserType") {
                if(data == 1){
                    data = "个人/专家";
                } else if(data == 2){
                    data = "企业";
                } else if(data == 3){
                    data = "服务机构";
                } else if(data == 4){
                    data = "高校院校";
                }
            }
            var replaceKey = "{"+key+"}";
            var replace = codeHtml.replace(replaceKey,data);
            codeHtml = replace;
        })
        $("#content").html(codeHtml);
        clickRegister();
    }

    function clickRegister(){
        // 同意
        $("#confirm").on("click", function () {
            reply(1,"",confirmCallback)
        })

        // 拒绝
        $("#refuse").on("click", function () {
            var messageText = $("#message-text").val();
            reply(0,messageText,refuseCallback)
        })
    }


    // 对接
    function reply(agreeOrRefuse,replyTxt,callback){
        var data = {
            id: id,
            replyTxt: replyTxt,
            agreeOrRefuse: agreeOrRefuse
        }
        let params = {
            type: "post",
            url: "/index/meeting/reply",
            contentType: "application/x-www-form-urlencoded",
            data: data,
            sCallback: function (data) {
                callback(data)
            },
            eCallback: function (res) {
            }
        }
        requset(params);
    }

    function confirmCallback(data){
        $('#conformMettingDlg').modal('hide');
        $('#contactInfo').css("display", "block");
    }
    function refuseCallback(data){
        $('#noMettingDlg').modal('hide');
    }

})
